package agh.rozproszony;

import agh.rozproszony.model.Message;
import agh.rozproszony.model.Reservation;
import agh.rozproszony.model.Room;
import agh.rozproszony.model.User;
import agh.rozproszony.DBStorage.DataBaseManager;
import agh.rozproszony.model.*;
import java.util.ArrayList;

public class MainDatabaseTest {

    /**
     * Punkt wejsciowy programu do testowania bazy danych
     */
    public static void main(String[] args) {

        DataBaseManager dataBase = new DataBaseManager();
        User myUser = null;
        Room myRoom = null;
        Reservation myReservation = null;
        Message myMessage = null;
        User myUser2 = null;
        User myUser3 = null;
        User myUser4 = new User();
        User myUser5 = new User();
        Message myMessage2 = null;
        ArrayList<Message> myMessagesList = new ArrayList();
        ArrayList<Message> myNotReadedMessages = new ArrayList();
        Invitation myInvitation = null;
        ArrayList<Invitation> myAwaitingInvitations = new ArrayList();

        try {
            myUser = dataBase.getUser(2);
            myRoom = dataBase.getRoom(2);
            myReservation = dataBase.getReservation(2);
            myMessage = dataBase.getMessage(1);
            myUser2 = dataBase.getUserByLogin("Login2");
            myUser3 = dataBase.getUserByEmail("Email2@com.pl");
            myUser4.setType(dataBase.getUserTypeByName("Login2"));
            myUser5.setType(dataBase.getUserTypeByID(2));
            myMessage2 = dataBase.getMessage("title2");
            myMessagesList = dataBase.getMessages(2);
            myNotReadedMessages = dataBase.getNotReadedMessages(2);
            myInvitation = dataBase.getInvitation(1);
            myAwaitingInvitations = dataBase.getAwaitingInvitations(1);

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Moj 1 uzytkownik w bazie to: " + myUser.getLogin() + " " + myUser.getEmail());
        System.out.println("Moj 1 pokoj w bazie to: " + myRoom.getId() + " " + myRoom.getName() + " " + myRoom.getCapacity());
        System.out.println("Moja rezervacja w bazie to: " + myReservation.getId() + " " + myReservation.getRoomId() + " " + myReservation.getOwnerId() + " " + myReservation.getYear() + " " + myReservation.getMonth() + " " + myReservation.getDay() + " " + myReservation.getFromHour() + " " + myReservation.getToHour());
        System.out.println("Moja wiadomosc w bazie to: " + myMessage.getTitle() + " " + myMessage.getContent());
        System.out.println("Moj 1 uzytkownik po loginie w bazie to: " + myUser2.getLogin() + " " + myUser2.getEmail());
        System.out.println("Moj 1 uzytkownik po emailu w bazie to: " + myUser3.getLogin() + " " + myUser3.getEmail());
        System.out.println("Moj 1 uzytkownik w bazie ma typ: " + myUser4.getType());
        System.out.println("Moj 2 uzytkownik w bazie ma typ: " + myUser5.getType());
        System.out.println("Moja wiadomosc po tytule w bazie to: " + myMessage2.getTitle() + " " + myMessage2.getContent());
        System.out.println("Moje zaproszenie: " + myInvitation.getReservationId()+ " " + myInvitation.getUserId() + " " + myInvitation.getTitle());
        
        /*
        int i = 0;
        while (i < myMessagesList.size()) {
            System.out.println("Moja wiadomosc do uzytkownika 1 w bazie to: " + myMessagesList.get(i).getTitle() + " " + myMessagesList.get(i).getContent());
            i++;
        }
        int j = 0;
        while (j < myNotReadedMessages.size()) {
            System.out.println("Moja NIE PRZECZYTANA wiadomosc do uzytkownika 1 w bazie to: " + myNotReadedMessages.get(j).getTitle() + " " + myNotReadedMessages.get(j).getContent());
            j++;
        }
        
        
        int k = 0;
        while (k< myAwaitingInvitations.size()) {
            try{
            System.out.println("Oczekujace zaproszenia: " + myAwaitingInvitations.size() + " do uzytkownia " + dataBase.getUser(myAwaitingInvitations.get(k).getUserId()).getLogin() +" o temacie: " + myAwaitingInvitations.get(k).getTitle());
            k++;
            }
            catch(SQLException e)
                    {
                    }
                    
        }*/
        /*
        try {
            dataBase.changePassword(myUser, "Password");
            System.out.println("Update Successful");

        } catch (Exception e) {
            e.printStackTrace();
        }*/
        /*
        try {
            dataBase.clearDatabase();
            System.out.println("Cleaning Successful");

        } catch (Exception e) {
            e.printStackTrace();
        }*/
        /*
        try {
            User myUser6=new User(-1,"Login4","Pass4","Email4@com.pl",0);
            dataBase.insertUser(myUser6);
            

        } catch (Exception e) {
            e.printStackTrace();
        }*/
        /*
        try {
            Message myMessage3 = new Message(-1,"title","content",1,2,0);
            dataBase.insertMessage(myMessage3);
            

        } catch (Exception e) {
            e.printStackTrace();
        }*/
/*
        try {
            Reservation myReservation2 = new Reservation(-1,1,1,2000,1,1,10,11); 
            dataBase.insertReservation(myReservation2);
            
            

        } catch (Exception e) {
            e.printStackTrace();
        }
        */
        /*
        try {
            Room myRoom2 = new Room(-1,"203",300);
            dataBase.insertRoom(myRoom2);
            
            

        } catch (Exception e) {
            e.printStackTrace();
        }
        */
        /*
        try {
            Invitation myInvitation= new Invitation(-1,1,1,true,"invit");
            dataBase.insertInvitiation(myInvitation);
            
            

        } catch (Exception e) {
            e.printStackTrace();
        }
        */
        /*
        try{
            dataBase.deleteRoom(myRoom);
            
            System.out.println("USUNIETO Z BAZY " +myRoom.getName());
            
        }catch(SQLException e)
                {
                    
                    
                }
        */
        /*
        try{
            dataBase.deleteUser(myUser);
            System.out.println("USUNIETO Z BAZY UZYTKOWNIKA "+ myUser.getLogin());
        }
        catch(SQLException e)
                {
                    
                    
                }
                
                */
        /*
        try{
            dataBase.deleteReservation(myReservation);
            System.out.println("USUNIETO Z BAZY REZERWACJE "+ myReservation.getId());
        }
        catch(SQLException e)
                {
                    
                    
                }*/
        /*
        Date Fromdata = new Date(113,4,1);
        Date Todata = new Date(113,5,27);
        ArrayList<Reservation> RsvList = new ArrayList();
        
        System.out.println(Fromdata);
        System.out.println(Todata);
        
        try {
            RsvList= (ArrayList<Reservation>) dataBase.getAllReservations(Fromdata, Todata);
        } catch (SQLException ex) {
            Logger.getLogger(MainDatabaseTest.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        System.out.println(RsvList.size());
        
        
        try {
            RsvList= (ArrayList<Reservation>) dataBase.getAllReservations(Fromdata, Todata, 1);
        } catch (SQLException ex) {
            Logger.getLogger(MainDatabaseTest.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        System.out.println(RsvList.size());
        */
        /*
        int liczba =0;
        try{
        liczba= dataBase.getReservationId(myReservation);
        }
        catch(SQLException ex)
                {
                
                }
                * 
                */
        /*
        try{
        dataBase.getRoomReservations(2, 27, 5, 2013);
        }
        catch(SQLException ex)
                {
                
                }
        */
        System.out.println();
    }
}
